package com.surfacing.rcp.client.modelManager;

import java.util.ArrayList;
import java.util.List;

import org.eclipse.swt.widgets.Display;

import com.surfacing.rcp.model.entity.Anforderung;

/**
 * This class manages the staff members
 * 
 * @author Michael
 */
public class AnforderungManager extends PropertyManager {
	// the item list
	private List<Anforderung> objectList = new ArrayList<Anforderung>();

	/**
	 * Adds a new anforderung to the list
	 * 
	 * @param anforderung
	 *            the staff member to add
	 */
	public void add(final Anforderung anforderung) {
		Display.getDefault().syncExec(new Runnable() {
			public void run() {
				objectList.add(anforderung);
				firePropertyChange("ANFORDERUNG_ADD", null, anforderung);
			}
		});
	}

	/**
	 * Removes the staff member from the list
	 * 
	 * @param anforderung
	 *            the member to remove
	 */
	public void remove(final Anforderung anforderung) {
		Display.getDefault().syncExec(new Runnable() {
			public void run() {
				objectList.remove(anforderung);
				firePropertyChange("ANFORDERUNG_REMOVE", anforderung, null);
			}
		});
	}

	/**
	 * Updates the staff member in the list
	 * 
	 * @param anforderung
	 *            the member to update
	 */
	public void update(final Anforderung anforderung) {
		Display.getDefault().syncExec(new Runnable() {
			public void run() {
				// assert we have this staff member
				if (!objectList.contains(anforderung))
					return;
				// get the position of the entry
				int id = objectList.indexOf(anforderung);
				objectList.set(id, anforderung);
				firePropertyChange("ANFORDERUNG_UPDATE", null, anforderung);
			}
		});
	}

	/**
	 * Removes all elements and resets the list
	 */
	public void removeAllElements() {
		objectList.clear();
		Display.getDefault().syncExec(new Runnable() {
			public void run() {
				firePropertyChange("ANFORDERUNG_CLEARED", null, null);
			}
		});
	}

	/**
	 * Converts the list to an array
	 * 
	 * @return the list as a array
	 */
	public Object[] toArray() {
		return objectList.toArray();
	}

	/**
	 * Returns a list with all staff members
	 * 
	 * @return a staff list
	 */
	public List<Anforderung> getAnforderungList() {
		return objectList;
	}
}
